package page.sample.ClientPage;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;

import page.sample.AuthorizationPage;
import dao.impl.ClientDao;
import entity.Client;
import entity.CreditCard;
import entity.Operations;

public class PayPage extends WebPage {

	public PayPage(final CreditCard creditCard, final Client client) {
		
		final Operations op = new Operations();
		final ClientDao clientDao = new ClientDao(app.MyFirstWebApplication.DATA_XML_FOLDER);
		final Operations oper = new Operations();
		final CreditCard CC = new CreditCard();
		Form<CreditCard> form = new Form("form", new CompoundPropertyModel<CreditCard>(CC));
		
		form.add(new TextField<Integer>("balance"));
		form.add(new TextField<Integer>("PIN"));
		
		
		
		form.add(new SubmitLink("pay") {

			@Override
			public void onSubmit() {
				super.onSubmit();
				if(CC.getPIN() == creditCard.getPIN())
				{
				op.pay(CC.getBalance(), creditCard.getAccount(), CC.getPIN(), client);
				clientDao.update(client);
					setResponsePage(new ShowCreditCardPage(client.getInfoUser()));
				}
				}
			});

		form.add(new Link("cancel") {

			public void onClick() {
				setResponsePage(new ShowCreditCardPage(client.getInfoUser()));
			}

		});
		
		
		add(new Link("ShowProfile") {

			@Override
			public void onClick() {
				setResponsePage(new ShowProfilePage(client.getInfoUser()));

			}

		});

		add(new Link("EditProfile") {

			@Override
			public void onClick() {
				setResponsePage(new EditProfilePage(client.getInfoUser()));

			}

		});

		add(new Link("exit") {

			@Override
			public void onClick() {
				setResponsePage(new AuthorizationPage());

			}

		});
		
		add(new Link("showCard")
		{

			@Override
			public void onClick() {
				setResponsePage(new ShowCreditCardPage(client.getInfoUser()));
				
			}
			
		});
		
		add(form);
	}

}
